﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace 学生成绩查询及选课系统.studetnOption
{
    public partial class selectedCourse : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            dataBind();

        }
        public void dataBind()
        {
            SqlDataSource1.ConnectionString = Conndb.strconn;
             //and g.stuno=@stuno
            SqlDataSource1.SelectCommand = "select c.cno as '课程ID',c.cname as '课程名',credit as '学分',cproperties as '课程性质' from course c join teacher t on c.tno=t.tno join grade g on g.cno=c.cno  where cproperties='选修' and status=1 and g.stuno="+Session["user"].ToString(); 
            SqlDataSource1.DataBind();
            
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string cno = ((Button)e.Item.FindControl("Button1")).CommandArgument.ToString();
            if (e.CommandName=="cancel")
            {
                string sqlCancel = "UPDATE dbo.grade SET status=0 WHERE  stuno=@stuno and cno=@cno";
                SqlParameter[] cancelArray = { new SqlParameter("@stuno", Session["user"].ToString()),
                                    new SqlParameter("@cno", cno) };
                int resCancel = DBAccess.GetState(sqlCancel, cancelArray);
                if (resCancel!=0)
                {
                    Label4.Text = "取消课程成功!";
                    string sql2 = "update course set cCount=cCount+1 where cproperties='选修'and cno=" + cno;
                    DBAccess.GetState(sql2);
                    Repeater1.DataBind();
                }
                else
                {
                    Label4.Text = "取消失败";
                    return;
                }
                        

                       
            }
        }
    }
}